package com.lnking.lnkingplace.Util;

import cn.hutool.core.codec.Base64;
import cn.hutool.extra.qrcode.QrCodeUtil;
import org.springframework.stereotype.Component;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;

@Component
public class QrcodeUtil {


    /**
     * 生成带id的二维码
     * @param id
     * @return
     */
    public String getQrCodeById(String id) throws Exception{
        BufferedImage image = QrCodeUtil.generate(id, 100, 100);
        //输出流
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        ImageIO.write(image, "png", stream);
        String base64 = Base64.encode(stream.toByteArray());

        return base64;
    }
}
